<?php

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Site;
use App\Models\Ad;

class AdsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 所有用户 ID
        $user_ids = User::all()->pluck('id')->toArray();
        // 所有站点
        $sites = Site::all();

        $faker = app(Faker\Generator::class);

        foreach($sites as $site) {
            $ads = factory(Ad::class)->times(rand(10,20))->make()->each(function ($ad, $index) use ($site) {
                $ad->user_id = $site->user_id;
                $ad->site_id = $site->id;
            });
            Ad::insert($ads->toArray());
        }
    }
}
